package com.ygxsk.carhome.ui.adapter;

import android.os.Build;
import android.widget.RadioButton;

import androidx.annotation.Nullable;

import com.blankj.utilcode.util.ColorUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.response.EvaReapirSatisfactionBean;
import com.ygxsk.carhome.views.RatingBarView;

import java.util.List;

/**
 * Autuhor:Administrator
 * Time:2021/10/19 0019  13:45
 * Description: this is 满意度的适配器内容
 */
public class SatisfactionAdapter extends BaseQuickAdapter<EvaReapirSatisfactionBean, BaseViewHolder> {


    //satisfactionadapter
    public SatisfactionAdapter(int layoutResId, @Nullable List<EvaReapirSatisfactionBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, EvaReapirSatisfactionBean evaReapirSatisfactionBean) {

        if (evaReapirSatisfactionBean != null) {

            //名称内容
            String satisfactionName = evaReapirSatisfactionBean.getSatisfactionName();

            //真实的等级
            int satisfaction = evaReapirSatisfactionBean.getSatisfaction();

            //是否选中的值内容
            int isCheckedValue = evaReapirSatisfactionBean.getIsChecked();

            //单独的按钮内容
            RadioButton radiaoButtonEvaInAdapter = (RadioButton) helper.getView(R.id.radiaobuttonevainadapter);
            radiaoButtonEvaInAdapter.setText(satisfactionName);

            //=========================================================================================
            //您对本次服务的评价是：
            //1         ○非常满意       ★★★★★
            //10        ○满意          ★★★★
            //2        ○一般           ★★★
            //3        ○不满意         ★★
            //30        ○非常不满意     ★

            //添加对 星星的查找
            RatingBarView ratingBarRight = (RatingBarView) helper.getView(R.id.ratingbarright);
            //这个是根据动态的值 设置数量多少个。
            if (satisfaction == 1) {//非常满意
                ratingBarRight.setSelectedCount(5 - 1);
            } else if (satisfaction == 10) {//满意
                ratingBarRight.setSelectedCount(4 - 1);
            } else if (satisfaction == 2) {//一般
                ratingBarRight.setSelectedCount(3 - 1);
            } else if (satisfaction == 3) {//不满意
                ratingBarRight.setSelectedCount(2 - 1);
            } else if (satisfaction == 30) {//非常不满意
                ratingBarRight.setSelectedCount(1 - 1);
            }
            //=========================================================================================

            if (isCheckedValue == 1) {//选中的颜色

                radiaoButtonEvaInAdapter.setChecked(true);
                //字体的颜色是变成红色的
                radiaoButtonEvaInAdapter.setTextColor(ColorUtils.getColor(R.color.red_nomal_nv));
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    radiaoButtonEvaInAdapter.setTextAppearance(R.style.txt_bold);
                }

            } else if (isCheckedValue == 0) {

                radiaoButtonEvaInAdapter.setChecked(false);
                //普通的字体颜色
                radiaoButtonEvaInAdapter.setTextColor(ColorUtils.getColor(R.color.dark));
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    radiaoButtonEvaInAdapter.setTextAppearance(R.style.txt_nomal);
                }

            } else {

                radiaoButtonEvaInAdapter.setChecked(false);
                //普通的字体颜色
                radiaoButtonEvaInAdapter.setTextColor(ColorUtils.getColor(R.color.dark));
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    radiaoButtonEvaInAdapter.setTextAppearance(R.style.txt_nomal);
                }

            }

        }

    }
}
